From f8b91b577b82dcaa8fef10ff35bfb7be1ddcb8a0 Mon Sep 17 00:00:00 2001 From: Eduardo Bautista Date: Thu, 28 May 2015 15:18:45 -0500 Subject: [PATCH] Use absolute path for CARGO_HOME --- src/cargo/util/config.rs | 10 ++++++---- tests/test_cargo_build_lib.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 7681bc0cb..35924a703 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -39,7 +39,7 @@ impl Config { })); let mut cfg = Config { - home_path: try!(homedir().chain_error(|| { + home_path: try!(homedir(cwd.as_path()).chain_error(|| { human("Cargo couldn't find your home directory. \ This probably means that $HOME was not set.") })), @@ -423,8 +423,10 @@ impl ConfigValue { } } -fn homedir() -> Option { - let cargo_home = env::var_os("CARGO_HOME").map(PathBuf::from); +fn homedir(cwd: &Path) -> Option { + let cargo_home = env::var_os("CARGO_HOME").map(|home| { + cwd.join(home) + }); let user_home = env::home_dir().map(|p| p.join(".cargo")); return cargo_home.or(user_home); } @@ -450,7 +452,7 @@ fn walk_tree(pwd: &Path, mut walk: F) -> CargoResult<()> // Once we're done, also be sure to walk the home directory even if it's not // in our history to be sure we pick up that standard location for // information. - let home = try!(homedir().chain_error(|| { + let home = try!(homedir(pwd).chain_error(|| { human("Cargo couldn't find your home directory. \ This probably means that $HOME was not set.") })); diff --git a/tests/test_cargo_build_lib.rs b/tests/test_cargo_build_lib.rs index 763fd0c17..476d2f14b 100644 --- a/tests/test_cargo_build_lib.rs +++ b/tests/test_cargo_build_lib.rs @@ -52,3 +52,33 @@ test!(build_with_no_lib { execs().with_status(101) .with_stderr("no library targets found")); }); + +test!(build_with_relative_cargo_home_path { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + + name = "foo" + version = "0.0.1" + authors = ["wycats@example.com"] + + [dependencies] + + "test-dependency" = { path = "src/test_dependency" } + "#) + .file("src/main.rs", r#" + fn main() {} + "#) + .file("src/test_dependency/src/lib.rs", r#" "#) + .file("src/test_dependency/Cargo.toml", r#" + [package] + + name = "test-dependency" + version = "0.0.1" + authors = ["wycats@example.com"] + "#); + + assert_that(p.cargo_process("build").env("CARGO_HOME", "./cargo_home/"), + execs() + .with_status(0)); +}); -- 2.30.2